﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using log4net;

namespace SysAdmin._04_Form._00_Common
{
    public class UICommonTool
    {
        private static ILog _logger = LogManager.GetLogger(typeof(UICommonTool));

        public static void ShowInfoDialog(string text)
        {
            InfoDialogForm form = new InfoDialogForm();
            form.Msg = text;
            form.ShowDialog();
        }

        public static void ShowAlertDialog(string text)
        {
            AlertDialogForm form = new AlertDialogForm();
            form.Msg = text;
            form.ShowDialog();
        }

        public static bool ShowConfirmDialog(string text)
        {
            ConfirmDialogForm form = new ConfirmDialogForm();
            form.Msg = text;
            DialogResult dr = form.ShowDialog();
            return dr == DialogResult.OK ? true : false;
        }

        public static void SetClipboardText(string text)
        {
            try
            {
                Clipboard.SetDataObject(text);
            }
            catch (System.Exception ex)
            {
                _logger.Error(ex);
            }
        }

        public static IList<TreeNode> GetAllTreeNodes(TreeView tv)
        {
            var ls = new List<TreeNode>();
            var queue = new Queue<TreeNode>();
            foreach (TreeNode item in tv.Nodes)
            {
                queue.Enqueue(item);
            }
            while (queue.Count > 0)
            {
                var item = queue.Dequeue();
                ls.Add(item);
                foreach (TreeNode item2 in item.Nodes)
                {
                    queue.Enqueue(item2);
                }
            }
            return ls;
        }
    }
}
